function H5File = loadH5File(ImgSetName, Aug, Patch, batch_size, solver_mode)

if nargin < 3, Aug = []; end
if nargin < 4, batch_size = 64; end

[xPatch, yPatch, real_ysize] = srdata.parsePatchSize(Patch);

%%
[bFound, ~, H5File] = myinput.searchDataByParam(srpath.getH5Path, 'st-*.mat', [ImgSetName '-*.h5'], Aug, xPatch, yPatch, batch_size);

%%
if bFound && exist(H5File, 'file')
    return
end

%%
ImgSetPath = srpath.getDataPath(ImgSetName, Aug);

%%
[Y, PatchPath] = srdata.loadHRPatches(ImgSetPath, Aug, yPatch);
X = srdata.loadLRPatches(Y, PatchPath, Aug, xPatch, solver_mode);
% h5file = '';
% return

%%
if all(size(X) == size(Y))
    X = cropImg(X, real_ysize);
end
Y = cropImg(Y, real_ysize);

%%
srimg.savemat2h5(H5File, X, Y, batch_size);

function X = cropImg(X, expected_size)
if length(expected_size) == 1
    expected_size = expected_size([1 1]);
end

imsize = size(X); imsize = imsize(1 : 2);
if all(expected_size == imsize)
    return
end

if any(expected_size > imsize)
    error('expected_size should be less than imsize!')
end

s = imsize - expected_size;
d1 = ceil(s / 2);
d2 = s - d1;
X = X(d1(1)+1 : end - d2(1), d1(2)+1 : end - d2(2), :);
